package
{
	/**
	 *
	 *@author CrazyChen 
	 *2013-4-10
	 */	
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	public class PlantItem extends Sprite
	{
		private var _cls:Class;
		
		public var bmp:Bitmap;
		
		public var hp:int;
		
		public var energy:int;
		
		public var gradAry:Array;
		
		public function PlantItem()
		{
			super();
			gradAry = [];
			this.buttonMode = true;
			bmp = new Bitmap();
			this.addChild(bmp);
			this.addEventListener(MouseEvent.MOUSE_DOWN,mouseDown);
			this.addEventListener(MouseEvent.MOUSE_UP,mouseUp);
		}
		
		private function mouseDown(e:MouseEvent):void{
			this.startDrag();
		}
		
		private function mouseUp(e:MouseEvent):void{
			this.stopDrag();
		}
	
		public function get cls():Class
		{
			return _cls;
		}

		public function set cls(value:Class):void
		{
			_cls = value;
			bmp.bitmapData = (new value()).bitmapData;
			for(var i:int=0;i<gradAry.length;i++){
				TowerWarMap.instance.gradMap.drawPlantGrad(gradAry[i]);
			}
			refreshBmpPosition();
		}
		
		public function refreshBmpPosition():void{
			bmp.x = -bmp.width/2;
			bmp.y = -bmp.height/2;
		}

	}
}